/**
 * Copyright (c) 2007, Ashish Lijhara
 * All rights reserved.
 *
 * TransparentJPanel.java
 *
 */

package crazy.java.Aetas;

import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.LayoutManager;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;

/**
 *
 * @author Ashish a.k.a Java Crazy
 */
public class TransparentJPanel extends JPanel{
    private BufferedImage image;
    public TransparentJPanel(){
        this(new FlowLayout(FlowLayout.CENTER));
        setOpaque(false);
    }
    public TransparentJPanel(LayoutManager layout){
        super(layout);
        setOpaque(false);
    }
    protected void paintComponent(Graphics g){
        if (image == null || image.getWidth() != getWidth() ||
                image.getHeight() !=getHeight()) {
            image = getGraphicsConfiguration().
                    createCompatibleImage(getWidth(), getHeight(),Transparency.TRANSLUCENT);
        }
        
        super.paintComponent(g);
        g.drawImage(image, 0, 0, null);
    }
}

